package com.mimc.controller.admin;

import com.jfinal.aop.Inject;
import com.mimc.common.utils.ip.IpUtils;
import com.mimc.core.model.SysLogininfor;
import com.mimc.core.service.SysLogininforService;
import com.mimc.framework.domain.AjaxResult;
import com.mimc.service.ShSysAdminService;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;

import java.util.Date;

@RequestMapping("/admin/login")
public class LoginController extends JbootController {
    @Inject
    private ShSysAdminService sysAdminService;
    @Inject
    private SysLogininforService sysLogininforService;
    public AjaxResult login(){
        String username=getPara("username");
        String password=getPara("password");
        String token=sysAdminService.login(username,password);
        AjaxResult ajaxResult=AjaxResult.success();
        ajaxResult.put("token",token);
        ajaxResult.put("username",username);
        //登录日志
        SysLogininfor sysLogininfor=new SysLogininfor();
        sysLogininfor.setUserName(username);
        sysLogininfor.setIpaddr(IpUtils.getIpAddr());
        sysLogininfor.setStatus("1");
        sysLogininfor.setMsg("登录成功");
        sysLogininfor.setLoginTime(new Date());
        sysLogininforService.save(sysLogininfor);
        return ajaxResult;
    }
}
